﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Admin_Comment : System.Web.UI.Page
{
    CommentBUS comBUS = new CommentBUS();
    DataTable tbComment = new DataTable();
    DataTable tbDetails = new DataTable();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            MultiView1.ActiveViewIndex = 0;
        }
        LoadData();
    }

    private void LoadData()
    {
        tbComment = comBUS.getAllComment();
        grvComment.DataSource = tbComment;
        grvComment.DataBind();
    }

   

    protected void grvComment_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grvComment.PageIndex = e.NewPageIndex;
        LoadData();
    }
    protected void grvComment_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("View"))
        {
            tbDetails = comBUS.getCommentById(Int32.Parse(e.CommandArgument.ToString()));
            lblMail.Text = tbDetails.Rows[0]["Comment_Mail"].ToString();
            lblTitle.Text = tbDetails.Rows[0]["Comment_Title"].ToString();
            lblContent.Text = tbDetails.Rows[0]["Comment_Content"].ToString();
            MultiView1.ActiveViewIndex = 1;
        }
        if (e.CommandName.Equals("Remove")) {
            bool check = comBUS.delComment(Int32.Parse(e.CommandArgument.ToString()));
            if (check) {
                LoadData();
            }
        }

    }
    protected void lbnSearch_Click(object sender, EventArgs e)
    {
        if (txtSearch.Value.Equals(""))
        {
            LoadData();
        }
        else
        {
            DataTable tbDetails = new DataTable();
            tbDetails = comBUS.getCommentByEmail(txtSearch.Value);
            grvComment.DataSource = tbDetails;
            grvComment.DataBind();
        }
    }
}